<?php

/**
 * @name MvcController
 * @author Roman Metlinskyi
 */
class MvcController extends Object implements IMvcController
{
  private static $config;

  protected $masterPage;

  public $Name;
  public $Type;

  public function __construct()
  {

  }

  protected function View($name = null)
  {
    return new MvcView($name, $this);
  }

  public static function Init($config)
  {
    self::$config = $config;
  }

  public static function Load($name) {

    $name = !empty($name) ? $name : self::$config->default;
    $type = ucfirst ("{$name}Controller");

    require_once self::$config->directory . "{$type}.php";

    $controller = new $type();
    if ($controller instanceof MvcController) {
      $controller->Name = $name;
      $controller->Type = $type;
      return $controller;
    }

    throw new Exception("{$name} controller not found");

  }
  
  
}